Skip to content

Add filter_by_search_query support to get_movies, get_episodes and get_tv_shows.#21

Open
anishsane wants to merge 1 commit into
OnFreund:masterfrom
anishsane:master
Open

Add filter_by_search_query support to get_movies, get_episodes and get_tv_shows.#21
anishsane wants to merge 1 commit into
OnFreund:masterfrom
anishsane:master

Conversation

@anishsane
Copy link
Copy Markdown

When calling these functions, the user can supply the optional string parameter - search_query.
If this parameter is provided, the results are filtered against the search_query parameter using a fuzzy search. This functionality will be used by Home Assistant for 'Search and Play' intent.

In addition to search_query, the user can also provide a parameter score_cutoff % (defaults to 80%) to be used as a threshold for fuzzy filtering.

Comment thread pykodi/kodi.py Outdated
Comment on lines +241 to +242
@staticmethod
def _filter_by_search_query(original_result, search_query=None, result_type=None, score_cutoff=100):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we use a static method here as opposed to a separate method?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer having a separate search method unless there's a good reason to go this route.

Copy link
Copy Markdown
Author

@anishsane anishsane Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a helper function. Hence prefixed by an _
I wanted to keep it under the Kodi class. So, not declared it as a global function.
But it did not need the self parameter. So, marked it as a static function.

If you prefer, I can make it a regular function and ignore the self parameter.

It will look like

- def _filter_by_search_query(original_result, search_query=None, result_type=None, score_cutoff=100):
+ def _filter_by_search_query(self, original_result, search_query=None, result_type=None, score_cutoff=100):
 # .... existing code here
...
...
- return Kodi._filter_by_search_query(results, search_query, 'movies', score_cutoff)
+ return self._filter_by_search_query(results, search_query, 'movies', score_cutoff)
# etc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code as per your suggestion. Let me know if this is better.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed the point. It's not about making this non-static (as you correctly mentioned, it doesn't use self), but rather adding a new, non-static, method, for search, rather than piggybacking on the existing ones.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I will attempt that.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the PR. Replaced my earlier logic entirely. Please take a look.

@anishsane anishsane marked this pull request as draft April 10, 2026 09:31
This function takes 2 arguments: media_type and search_query.
Currently media_type can take the value 'movies', 'tvshows' or 'episodes'. (The logic can be extended later.)

The results of the corresponding get_*<media type> are filtered against
the search query by a fuzzy match logic. This functionality will be used
by Home Assistant for the 'Search and play' intent.

In addition to search_query, the user can also provide a parameter
score_cutoff % (defaults to 80%) to be used as a threshold for fuzzy
filtering.
@anishsane anishsane marked this pull request as ready for review April 10, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants